package com.tz.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.*;

@Entity
@Table(name="TBL_CATEGORY")
public class Category implements Serializable{

	private static final long serialVersionUID = -2818964476201353639L;

	private long id;

	private String name;

	private Category parent;

	private List<Category> children;

	public Category() {

	}

	

	public Category(long id, String name, Category parent) {
		super();
		this.id = id;
		this.name = name;
		this.parent = parent;
	}


	public Category(long id, String name, List<Category> children) {
		super();
		this.id = id;
		this.name = name;
		this.children = children;
	}

	
	@Id
	public long getId() {
		return id;
	}



	public void setId(long id) {
		this.id = id;
	}


	@Column(name="c_name",nullable=false,unique=true)
	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}


	@ManyToOne
	@JoinColumn(name="parent")
	public Category getParent() {
		return parent;
	}



	public void setParent(Category parent) {
		this.parent = parent;
	}


	@OneToMany(mappedBy="parent")
	public List<Category> getChildren() {
		return children;
	}



	public void setChildren(List<Category> children) {
		this.children = children;
	}


	@Override
	public String toString() {
		return "Category{" +
				"id=" + id +
				", name='" + name + '\'' +
				'}';
	}
}
